﻿@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    List<WeChatParking.Entity.Enterprise> list = ViewBag.EnterpriseList;
}
<div class="">
    <div class="ibox-content">
        <div class="jqGrid_wrapper">
            <div class="col-sm-12 jqGrid-toolbar">
                <form class="form-inline search-form" id="search-form">
                    <div class="form-group">
                        <label for="search_order_id">代码</label>
                        <input type="text" class="form-control" name="enterprise_Code">
                    </div>
                    <div class="form-group">
                        <label for="search_user_name">名称</label>
                        <input type="text" class="form-control" name="enterprise_Name">
                    </div>

                    <button type="submit" class="btn btn-primary">
                        <i class="glyphicon glyphicon-search"></i>查询
                    </button>
                </form>
                <div class="btn-group " role="group">
                    <button class="btn btn-primary" id="btn-add">
                        <i class="glyphicon glyphicon-plus"></i>新增
                    </button>
                    <button class="btn btn-success" id="btn-edit">
                        <i class="glyphicon glyphicon-pencil"></i>编辑
                    </button>
                    <button class="btn btn-danger" id="btn-del">
                        <i class="glyphicon glyphicon-trash"></i>删除
                    </button>
                </div>
            </div>
            <table id="grid"></table>
            <div id="grid_pager"></div>
        </div>
    </div>
</div>
<div class="modal fade" id="form-modal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">物业信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" method="post" action="/Admin/SaveParking">
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">物业代码：</label>
                            <div class="col-sm-9">
                                <input type="text" name="Enterprise_Code" id="enterprise_Code" class="form-control" placeholder="请输入物业代码" required maxlength="50">
                                <input type="hidden" id="ID" name="ID" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-9">
                                <input type="text" id="Enterprise_Name" name="Enterprise_Name" class="form-control" placeholder="请输入名称" required maxlength="50">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">父级物业：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="Enterprise_FCode">
                                    @foreach (var item in list)
                                    {
                                        <option value="@item.Enterprise_Code">@item.Enterprise_Name</option>
                                    }

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系人姓名：</label>
                            <div class="col-sm-9">
                                <input type="text" name="Contact_name" class="form-control" placeholder="请输入联系人姓名" required maxlength="50">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系人qq：</label>
                            <div class="col-sm-9">
                                <input type="text" name="Contact_qq" class="form-control" placeholder="请输入联系人qq" required maxlength="50">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系方式：</label>
                            <div class="col-sm-9">
                                <input type="text" name="Contact_phone" class="form-control" placeholder="请输入联系方式" required maxlength="11">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系人邮箱：</label>
                            <div class="col-sm-9">
                                <input type="text" name="Contact_emaill" class="form-control" placeholder="请输入联系方式" required maxlength="11">
                            </div>
                        </div>
                          @*  <div class="form-group">
                            <label class="col-sm-3 control-label">标准计费模式：</label>
                            <div class="col-sm-9">
                                <input type="checkbox" name="ISBiaoZhunFee" class="form-control">
                            </div>
                        </div>*@
                        <input type="hidden" name="ISBiaoZhunFee" class="form-control">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">支付方式：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="payType">
                                    <option value="1">微信支付</option>
                                    <option value="2">通联支付</option>
                                    <option value="3">无感支付</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="btn-save">保存</button>
            </div>
        </div>
    </div>
</div>
<div id="form-config-dialog" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
@section BodyFooter{
    <script>
        $(document).ready(function () {

            $("#grid").jqGrid({
                url: '/Admin/ParkingQuery',
                colNames: ["ID", "代码", "名称", "父级代码", "联系人", "联系人qq", "联系人电话", "联系人邮箱", "创建时间", "扩展配置"],
                colModel: [{
                    name: "ID",
                    index: "ID",
                    key: true,
                    width: 30
                },
                {
                    name: "Enterprise_Code",
                    index: "Enterprise_Code",
                    width: 120
                },
                {
                    name: "Enterprise_Name",
                    index: "Enterprise_Name",
                    width: 120
                },
                {
                    name: "Enterprise_FCode",
                    index: "Enterprise_FCode",
                    width: 80
                },
                {
                    name: "Contact_name",
                    index: "Contact_name",
                    width: 80
                },
                 {
                     name: "Contact_qq",
                     index: "Contact_qq",
                     width: 80
                 },
                  {
                      name: "Contact_phone",
                      index: "Contact_phone",
                      width: 80
                  },
                  {
                      name: "Contact_emaill",
                      index: "Contact_emaill",
                      width: 80
                  },
                {
                    name: "create_time",
                    index: "create_time",
                    width: 80,
                    formatter: 'date',
                    formatoptions: { newformat: 'Y-m-d H:i:s' }
                },
                {
                    name: "ID",
                    index: "ID",
                    width: 90,
                    sortable: false,
                    formatter: renderConfigCol
                }
                ],
                caption: "企业信息",
            });

            $("#grid").adaptGridSizeInWindow();
        });
        $('#search-form').submit(function () {
            var data = $(this).serializeArray();
            var postData = {};
            $.each(data, function (i, n) {
                postData[n.name] = n.value;
            });

            $("#grid").jqGrid('setGridParam', {
                postData: postData, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入


            return false;
        });
        $('#btn-add').click(function () {
            document.getElementById("ID").value = 0;
            document.getElementById("enterprise_Code").disabled = false;
            $('#form-modal').toggleModal(true, ' 新 增 ');
            $('#form-modal form').bindData(null);

        });
        $('#btn-edit').click(function () {
            var row = $("#grid").getGridSelectedData();
            if (!row)
                return;
            document.getElementById("enterprise_Code").disabled = true;
            $('#form-modal form').bindData(row);
            $('#form-modal').toggleModal(true, ' 编 辑 ');
        });

        $.validator.setDefaults({
            submitHandler: function (form) {
                $(form).ajaxSubmit(function (d) {
                    $("#grid").trigger("reloadGrid");
                    $('#form-modal').toggleModal(false);
                    toastr.info('数据保存成功');
                });
            }
        });
        $('#form-modal form').validate()

        $('#btn-save').click(function (form) {
            $('#form-modal form').submit();
        });
        $('#btn-del').click(function () {
            var ids = $("#grid").jqGrid('getGridParam', 'selarrrow');
            if (ids.length == 0)
                return;
            $.confirm('确认删除数据？', function () {
                $.postJsonAjax('/Admin/DeleteParking', { ids: ids.join(',') }, function (data) {
                    $("#grid").trigger("reloadGrid");
                    if (data.Code == 1) {
                        toastr.info('数据删除成功');
                    } else {
                        toastr.error(data.Message);
                    }

                });
            });
        });
    </script>


    <script>
        function renderConfigCol(cellvalue, options, rowObject) {
            var ID = rowObject['ID'];
            var name = rowObject['Enterprise_Name'];

            var code = rowObject['Enterprise_FCode'];
            if (code == "0") {
                return "";
            } else {
                return '<button type="button" class="btn btn-primary btn-xs config-icon-item" data-enterid="' + ID + '" data-entername="' + name + '"><i class="fa fa-cog"></i><span> 停车场扩展配置</span></button>';
            }
        }

        $(function () {
            $(document).on('click', '.config-icon-item', function () {
                var url = '/Admin/ParkingConfig?id=' + $(this).attr('data-enterid');
                var title = $(this).attr('data-entername');
                $('#form-config-dialog .modal-content').load(url, function () {
                    $('#form-config-dialog').toggleModal(true, '停车场扩展配置： ' + title);

                });
            });

            $('#form-config-dialog').on('click', '#btn-config-save', function () {
                $('#form-config-dialog form').ajaxSubmit(function (d) {
                    if (d.Code == 1) {
                        $('#form-config-dialog').toggleModal(false);
                        toastr.info('数据保存成功');
                    } else {
                        toastr.warning(d.Message);
                    }
                });
            });
        });
    </script>

}
